package com.isometricProjectionExmaple
{
	//对角对象
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class IsoObject extends Sprite
	{
		protected var _position:Point3D;
		protected var _size:Number;
		protected var _walkable:Boolean;
		public function IsoObject(size:Number)
		{
			this._size = size;
			this._position = new Point3D();
			this.updateScreenPosition();
		}
		
		/**更新物体在屏幕中的显示位置**/
		protected function updateScreenPosition():void
		{
			var screenPos:Point = IsoUtils.isoToScreen(this._position);
			super.x = screenPos.x;
			super.y = screenPos.y;
		}
		
		/**重写String()**/
		override public function toString():String
		{
			return "[IsoObject(x:"+this._position.x +",y:"+this._position.y +",z:"+this._position.z+")]"
		}
		
		/**
		 * 设置3d空间中的x点
		 * */
		override public function set x(value:Number):void
		{
			this._position.x = value;
			this.updateScreenPosition();
		}
		
		override public function get x():Number
		{
			return this._position.x;
		}
		
		/**
		 * 设置3d空间中的y点
		 * */
		override public function set y(value:Number):void
		{
			this._position.y = value;
			this.updateScreenPosition();
		}
		
		override public function get y():Number
		{
			return this._position.y;
		}
		
		/**
		 * 设置3d空间中的x点
		 * */
		override public function set z(value:Number):void
		{
			this._position.z = value;
			this.updateScreenPosition();
		}
		
		override public function get z():Number
		{
			return this._position.z;
		}
		
		/**设置对象的位置**/
		 public function set position(value:Point3D):void
		{
			this._position = value;
			this.updateScreenPosition();
		}
		
		 public function get position():Point3D
		{
			return this._position;
		}
		
		/**返回深度**/
		public function get depth():Number
		{
			return (this._position.x +this._position.z) * 0.886 - this._position.y * 0.707;
		}
		
		/**设置是否可通过**/
		public function set walkable(boo:Boolean):void
		{
			 this._walkable = boo;
		}
		
		 public function get walkable():Boolean
		{
			return this._walkable;
		}
		
		/**设置对象的尺寸**/
		 public function set size(value:Number):void
		{
			this._size = value;
			
		}
		
		 public function get size():Number
		{
			return this._size;
		}
		
		/**返回矩形 基于x-z下的平面**/
		public function get rect():Rectangle
		{
			return new Rectangle(x-size/2,z-size/2,size,size);
		}
	}
}